#!/bin/bash
clear

TEXT='\033[30;107;2m'
INFO='\033[97;44m'
WARNING='\033[97;43m'
ERROR='\033[97;41m'
SUCCESS='\033[97;42m'
GREEN='\033[92m'
YELLOW='\033[93m'
RESET='\033[0m'

if [ "${EUID}" -ne 0 ]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} You need to run this script as root! ${RESET}"; exit 1
fi

read -p "Masukkan nama pengguna: " _namapengguna
egrep "^$_namapengguna" /etc/passwd >/dev/null
if [ $? -ne 0 ]; then
    echo -e "${ERROR} RALAT ${RESET}${TEXT} Nama pengguna tidak wujud! ${RESET}"; exit 1
fi
read -p "Masukkan tempoh aktif [Hari]: " _tempohaktif
tarikh_luput=$(date -d "$_tempohaktif days" +"%F")

passwd -u $_namapengguna
usermod -e $tarikh_luput $_namapengguna

clear
echo
echo -e "${TEXT} ========================================================== ${RESET}"
echo -e "${TEXT} PERBAHARUI AKAUN                                           ${RESET}"
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo
echo -e "${YELLOW} Nama pengguna:${RESET} ${GREEN}$_namapengguna${RESET}"
echo -e "${YELLOW}  Tempoh aktif:${RESET} ${GREEN}$_tempohaktif days${RESET}"
echo -e "${YELLOW}  Tarikh luput:${RESET} ${GREEN}$tarikh_luput${RESET}"
echo
echo -e "${TEXT} ---------------------------------------------------------- ${RESET}"
echo -e "${TEXT} Created by Doctype, Powered by Cybertize.                  ${RESET}"
echo -e "${TEXT} Copyright 2021, Allright Reserved.                         ${RESET}"
echo -e "${TEXT} ========================================================== ${RESET}"
echo